package com.leo.foodmaster.admin.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leo.foodmaster.commons.entity.Result;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.bind.annotation.PostMapping;
import com.leo.foodmaster.admin.system.entity.SysConfigEntity;
import com.leo.foodmaster.admin.system.service.ISysConfigService;
import com.leo.foodmaster.admin.system.mapper.SysConfigMapper;
import javax.annotation.Resource;

/**
 * 参数配置表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2021-12-22
 */
@RestController
@RequestMapping("/api/system/config")
@Api(tags = "参数配置表")
@Slf4j
public class SysConfigController {
    @Resource
    private ISysConfigService isysConfigService;
    @Resource
    private SysConfigMapper sysConfigMapper ;


    @GetMapping("/page")
    @ApiOperation("分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "current", value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
        @ApiImplicitParam(name = "size", value = "每页显示记录数", paramType = "query",required = true, dataType="int")
    })
    public Result<IPage<SysConfigEntity>> page(@ApiIgnore Page<SysConfigEntity> page, @ApiIgnore SysConfigEntity sysConfigEntity){
        //单表查询
    	IPage<SysConfigEntity> pageList = isysConfigService.page(page,sysConfigEntity);
        return Result.success(pageList);
    }


    @GetMapping
    @ApiOperation("信息")
    public Result<SysConfigEntity> get(@RequestParam Long id){
    	SysConfigEntity sysConfigEntity = isysConfigService.getById(id);
    	return Result.success(sysConfigEntity);
    }

    @PostMapping
    @ApiOperation("保存")
    public Result<Boolean> save(@ApiIgnore @RequestBody SysConfigEntity sysConfigEntity){
        Boolean save = isysConfigService.save(sysConfigEntity);
        return  Result.success(save);
    }


    @PutMapping
    @ApiOperation("修改")
    public Result<Boolean> update(@ApiIgnore @RequestBody SysConfigEntity sysConfigEntity){
        boolean updateById = isysConfigService.updateById(sysConfigEntity);
        return  Result.success(updateById);
    }


    @DeleteMapping
    @ApiOperation("删除")
    public Result<Integer> delete(@RequestBody Integer[] ids){
    	List<Integer> asList = Arrays.asList(ids);
    	int deleteBatchIds = sysConfigMapper.deleteBatchIds(asList);
    	return Result.success(deleteBatchIds);
    }

}
